package logic

import (
	"context"
	"gorm.io/gorm"
	"wechatdev/model/mysql"

	"wechatdev/wechatdevrpc/internal/svc"
	"wechatdev/wechatdevrpc/wechatdevrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type PerfacetLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewPerfacetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PerfacetLogic {
	return &PerfacetLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *PerfacetLogic) Perfacet(in *wechatdevrpc.PerfacetRequest) (*wechatdevrpc.PerfacetResponse, error) {
	// todo: add your logic here and delete this line
	user := mysql.User{
		Model:     gorm.Model{ID: uint(in.UserId)},
		HeadImage: in.HeadImage,
		NickName:  in.NickName,
		Address:   in.Address,
		Mobile:    in.Mobile,
		Password:  in.Password,
		WxCode:    in.WxCode,
		Qq:        in.Qq,
		Email:     in.Email,
	}
	err := user.UserPerfacet(mysql.DB)
	if err != nil {
		return nil, err
	}
	return &wechatdevrpc.PerfacetResponse{
		UserId: int64(user.ID),
	}, nil
}
